<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/* @var $block \Magento\Catalog\Block\Product\AbstractProduct */
?>

<?php
switch ($type = $block->getType()) {

    case 'related-rule':
        if ($exist = $block->hasItems()) {
            $type = 'related';
            $class = $type;

            $image = 'related_products_list';
            $title = __('Customers Also Viewed');
            $items = $block->getAllItems();
            $limit = $block->getPositionLimit();
            $shuffle = (int) $block->isShuffled();
            $canItemsAddToCart = $block->canItemsAddToCart();

            $showAddTo = true;
            $showCart = true;
            $templateType = null;
            $description = false;
        }
    break;

    case 'related':
        /** @var \Magento\Catalog\Block\Product\ProductList\Related $block */
        if ($exist = $block->getItems()->getSize()) {
            $type = 'related';
            $class = $type;

            $image = 'related_products_list';
            $title = __('Customers Also Viewed');
            $items = $block->getItems();
            $limit = 0;
            $shuffle = 0;
            $canItemsAddToCart = $block->canItemsAddToCart();

            $showAddTo = true;
            $showCart = true;
            $templateType = null;
            $description = false;
        }
    break;
    
    case 'upsell-rule':
        if ($exist = $block->hasItems()) {
            $type = 'upsell';
            $class = $type;

            $image = 'upsell_products_list';
            $title = __('We found other products you might like!');
            $items = $block->getAllItems();
            $limit = $block->getPositionLimit();
            $shuffle = (int) $block->isShuffled();

            $showAddTo = true;
            $showCart = true;
            $templateType = null;
            $description = false;
            $canItemsAddToCart = false;
        }
    break;

    case 'upsell':
        /** @var \Magento\Catalog\Block\Product\ProductList\Upsell $block */
        if ($exist = count($block->getItemCollection()->getItems())) {
            $type = 'upsell';
            $class = $type;

            $image = 'upsell_products_list';
            $title = __('We found other products you might like!');
            $items = $block->getItemCollection()->getItems();
            $limit = $block->getItemLimit('upsell');
            $shuffle = 0;

            $showAddTo = true;
            $showCart = true;
            $templateType = null;
            $description = false;
            $canItemsAddToCart = false;
        }
    break;
    
    case 'crosssell-rule':
        /** @var \Magento\Catalog\Block\Product\ProductList\Crosssell $block */
        if ($exist = $block->hasItems()) {
            $type = 'crosssell';
            $class = $type;

            $image = 'cart_cross_sell_products';
            $title = __('New Arrivals');
            $items = $block->getItemCollection();

            $showAddTo = true;
            $showCart = true;
            $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
            $description = false;
            $canItemsAddToCart = false;
        }
    break;

    case 'crosssell':
        /** @var \Magento\Catalog\Block\Product\ProductList\Crosssell $block */
        if ($exist = $block->getItemCount()) {
            $type = 'crosssell';
            $class = $type;

            $image = 'cart_cross_sell_products';
            $title = __('New Arrivals');
            $items = $block->getItems();

            $showAddTo = true;
            $showCart = true;
            $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
            $description = false;
            $canItemsAddToCart = false;
        }
    break;
    
    case 'other':
    break;
}
?>

<?php if ($exist){?>
<?php if ($type == 'related' || $type == 'upsell'){ ?>
        <h2 style="text-align: center;font-size: 15px;font-weight: bold"><?php /* @escapeNotVerified */ echo $title; ?></h2>
        <div class="swiper-container" id="<?php echo $type;?>" style="height: 250px">
        <!-- Additional required wrapper -->
        <div class="swiper-wrapper">
            <!-- Slides -->
            <?php foreach ($items as $_item): ?>
                <div class="swiper-slide item product product-item"  style="padding: 5px">
                    <a href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($_item) ?>" class="product photo product-item-photo" >
                        <?php echo $block->getImage($_item, $image)->toHtml(); ?>
                    </a>
                    <div class="product details product-item-details">
                        <strong class="product name product-item-name" style="    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;"><a class="product-item-link" title="<?php echo $block->escapeHtml($_item->getName()) ?>" href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($_item) ?>">
                                <?php echo $block->escapeHtml($_item->getName()) ?></a>
                        </strong>

                        <?php /* @escapeNotVerified */ echo $block->getProductPrice($_item); ?>

                        <?php if ($templateType): ?>
                            <?php echo $block->getReviewsSummaryHtml($_item, $templateType) ?>
                        <?php endif; ?>


                    </div>
                </div>
            <?php endforeach; ?>

        </div>

        <div class="swiper-pagination"></div>



    </div>
                <script>
                    require(["jquery",'swiper'],function($,Swiper){
                        new Swiper('#<?php echo $type;?>', {
                            // Optional parameters
                            direction: 'horizontal',
                            loop: true,
                            slidesPerView : 3,
                         //   slidesPerGroup: 3,
                            // If we need pagination
                            pagination: {
                                el: '.swiper-pagination',
                            },
                        })
                    }
                    )
                </script>
    <?php }?>
<?php }?>